<template>
  <view class="nav-bar">
    <view class="back-btn" @tap="goBack">
      <image class="back-icon" src="/static/icon/返回_return.svg"></image>
    </view>
    <text class="nav-title">{{ title }}</text>
  </view>
</template>

<script>
export default {
  name: 'NavBar',
  props: {
    // 标题
    title: {
      type: String,
      default: ''
    },
    // 返回路径
    backUrl: {
      type: String,
      default: ''
    },
    // 是否是tabbar页面
    isTabbar: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    // 返回上一页
    goBack() {
      if (this.backUrl) {
        if (this.isTabbar) {
          uni.switchTab({
            url: this.backUrl
          });
        } else {
          uni.navigateTo({
            url: this.backUrl
          });
        }
      } else {
        uni.navigateBack({ delta: 1 });
      }
    }
  }
}
</script>

<style lang="scss">
.nav-bar {
  display: flex;
  align-items: center;
  height: 88rpx;
  background: #FFFFFF;
  padding: 0 30rpx;
  position: relative;
  
  .back-btn {
    width: 60rpx;
    height: 60rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    left: 30rpx;
    z-index: 10;
    
    .back-icon {
      width: 40rpx;
      height: 40rpx;
      filter: brightness(0) invert(0); /* 恢复图标原始颜色 */
    }
    
    &:active {
      opacity: 0.8;
    }
  }
  
  .nav-title {
    flex: 1;
    text-align: center;
    font-size: 32rpx;
    font-weight: 500;
    color: #333;
    position: absolute;
    left: 0;
    right: 0;
    z-index: 1;
  }
}
</style> 